<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <#include "/pubHeadStyleTree.html">
</head>
<body>
<div style="position: relative;height: 100%;">
    <div class="ccpui-trees" >
            <p class="isShowTree colorSwitch">
                <span style="float: left;color: #fff">&nbsp;&nbsp;表单分类管理</span>
                <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
            </p>
            <div style="margin-top: 6px;" >
                <ul class="ccpui-iconTree iconTrees">
                    <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                    <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                    <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                </ul>
                <ul id="formTypeTree" class="ztree ccpui-listZtree" style="height: 431px"></ul>
            </div>
    </div>
    <div class="ccpui-coreContent" style="position: absolute;top:10px;right:10px;bottom: 0;left: 250px">
        <table id="formList" lay-filter="formList" ></table>
    </div>
</div>
<div class="layui-btn-container" style="position: absolute;bottom: 0;left:45%">
    <a class="layui-btn layui-btn-sm" id="select">选择</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" id="cancel">取消</a>
</div>
<script type="text/html" id="customHeaderTool">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
    </div>
    <form class="layui-form" action="" style="margin-top:10px">
        <div class="table-top-filter">
            <div class="table-filter-alone">
                <label class="layui-form-label">标题:</label>
                <input type="text" name="subject" id="subject" class="layui-input filter-value" placeholder="标题"
                       autocomplete="off"/>
            </div>
        </div>
    </form>
</script>
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'table', 'layer', 'jquery', 'form', 'tree','commons', 'totalFilter', 'setter'], function () {
        var table = layui.table, layer = layui.layer, setter = layui.setter, commons = layui.commons,
            totalFilter = layui.totalFilter, form = layui.form;

        var formType = '${formType!}';

        $("#cancel").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

        //刷新
        $(".zTree-refresh").click(function () {
            resZtrees();
        });
        //展开
        $(".zTree-triangle-d").click(function () {
            $.fn.zTree.getZTreeObj("formTypeTree").expandAll(true);
        });
        //收起
        $(".zTree-triangle-r").click(function () {
            $.fn.zTree.getZTreeObj("formTypeTree").expandAll(false);
        });

        var selectedFormId;
        var selectedFormSubject;
        var selectedFormKey;
        var selectedTableId;
        table.on('radio(formList)',function (obj) {
            var data = obj.data;
            selectedFormId = data.formDefId;
            selectedFormSubject = data.subject;
            selectedFormKey = data.formKey;
            selectedTableId = data.tableId;
        });

        $("#select").click(function () {
            switch (formType) {
                case "0":
                    parent.setGlobalFormValue(selectedFormId, selectedFormSubject, selectedFormKey,selectedTableId);
                    break;
                case "1":
                    parent.setBpmFormValue(selectedFormId, selectedFormSubject, selectedFormKey,selectedTableId);
                    break;
                case "2":
                    parent.setNodeFormValue(selectedFormId, selectedFormSubject, selectedFormKey,selectedTableId);
                    break;
                default:
                    break;
            }

            parent.layer.close(parent.layer.getFrameIndex(window.name));

        });

        resZtrees();
        loadTable(serverPath.formPath + setter.formLinkPath +'formDef/list?isPublished=1');
        // totalFilter.init();
        function resZtrees() {
            $.ajax({
                url: serverPath.formPath + setter.sysLinkPath +"globalType/list",
                type: "post",
                dataType: 'json',
                data: {"catKey": "FORM_TYPE", "hasRoot": 1},
                success: function (data) {
                    var zNodes = data.data;
                    var setting = {
                        view: {
                            showLine: false,
                            nameIsHTML: true, //允许name支持html
                            selectedMulti: false
                        },
                        edit: {
                            enable: false,
                            editNameSelectAll: false
                        },
                        data: {
                            simpleData: {
                                enable: true,
                                idKey: "typeId",
                                pIdKey: "parentId"

                            },
                            key: {
                                name: "typeName"
                            }
                        },

                        callback: {
                            onClick: onClickType
                        }
                    };
                    $.fn.zTree.init($('#formTypeTree'), setting, zNodes);
                }
            });
        }
        var typeId = "";
        var typeName = "";
        function onClickType(event, treeId, treeNode) {
            typeId = treeNode.typeId;
            typeName = treeNode.nodeKey;
            var url = serverPath.formPath + setter.formLinkPath +'formDef/list?categoryId=' + typeId;
            if (null == treeNode.parentId) {
                url = serverPath.formPath + setter.formLinkPath +'formDef/list';
            }
            loadTable(url);
        }
        //树状菜单隐藏
        var treeval = true;
        $(".treeone").click(function () {
            treeval = tresStyle(treeval, ".treeone");
        });
        function onClickRess(event, treeId, treeNode, clickFlag) {
            selectOrgId = treeNode.orgId;
        }
        function loadTable(url) {
            table.render({
                elem: '#formList'
                , url: url
                , title: '表单选择'
                ,height:'full-75'
                , defaultToolbar: []
                , toolbar: '#customHeaderTool'
                , cols: [[
                    {type: 'radio', fixed: 'left'}
                    , {field: 'formDefId', title: 'ID', hide:true, align: 'center'}
                    , {field: 'subject', title: '表单标题', align: 'center'}
                    , {field: 'formDesc', title: '描述', align: 'center'}
                ]]
                , page: true
            });
        }

        //头工具栏事件
        table.on('toolbar(formList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    table.reload("formList", {
                        where: {
                            Q_name_SL: $("#subject").val()
                        },
                        page: {
                            curr: 1
                        }
                    });
                    break;
            }
        })
    });
</script>
<style>
    .layui-table-tool-temp{
        padding: 0;
    }
    .table-top-filter{
        text-align: center;
    }
    .table-top-filter label.layui-form-label{
        width: auto;
        padding-left: 0;
    }
    /*div#classRightMenus {*/
    /*position: fixed;*/
    /*border: 1px solid #ccc;*/
    /*z-index: 900;*/
    /*visibility: hidden;*/
    /*top: 0;*/
    /*background-color: #f5f5f5;*/
    /*text-align: left;*/
    /*padding: 2px;*/
    /*}*/

    /*div#classRightMenus ul li {*/
    /*margin: 5px 0;*/
    /*padding: 0 8px;*/
    /*cursor: pointer;*/
    /*list-style: none outside none;*/

    /*}*/
    /*.trees .iconTrees li {*/
    /*display: inline-block;*/
    /*margin: 6px 3px;*/
    /*cursor: pointer;*/
    /*}*/
    /*#processTree {*/
    /*position: absolute;*/
    /*background: #fff;*/
    /*bottom:0px;*/
    /*top:70px;*/
    /*right: 0;*/
    /*left: 0;*/
    /*overflow: auto;*/
    /*height: 300px;*/
    /*}*/
    /*.table-top-filter .layui-form-label {*/
    /*width: 62px;*/
    /*}*/



    /*.table-top-filter label.layui-form-label {*/
    /*width: 104px;*/
    /*float: left;*/
    /*}*/

    /*.tablesize .layui-table-view {*/
    /*margin-right: 10px;*/
    /*}*/
    /*.layui-table-tool-temp{*/
    /*padding-right:0;*/
    /*}*/
</style>
</body>
</html>